import { Ref, ref } from "vue";
import { DocModel } from "./docs";
import { NoteModel } from "./Note";
import { ToolModel } from "./tool";
import { UserModel } from "./user";


class AppRef {
  private static _ins: Ref = ref(new AppRef());
  private _user: UserModel = new UserModel();
  private _note: NoteModel = new NoteModel();
  private _tool: ToolModel = new ToolModel();
  private _doc: DocModel = new DocModel();

  constructor() { }

  /** 退出时 需将实例全部清除 */
  public loginOut(): void {
    this._user = new UserModel();
  }

  public static get ins(): AppRef {
    return this._ins?.value ? this._ins.value : this._ins.value = new AppRef();
  }
  /** 用户 */
  public get user(): UserModel {
    return this._user;
  }
  /** 便签 / 留言 */
  public get note(): NoteModel {
    return this._note;
  }
  /** 工具 */
  public get tool(): ToolModel {
    return this._tool;
  }
  /** 文档 */
  public get doc(): DocModel {
    return this._doc;
  }
}
/** 响应式 状态管理池 */
export const appRef: AppRef = AppRef.ins;